package com.zhangzhan.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.zhangzhan.domain.commcon.ResponseResult;
import com.zhangzhan.domain.dto.ChangeStatusDto;
import com.zhangzhan.domain.dto.RoleLikeDto;
import com.zhangzhan.domain.dto.SaveRoleMenuDto;
import com.zhangzhan.domain.dto.UpdateRoleMenuDto;
import com.zhangzhan.domain.vo.PageVO;
import com.zhangzhan.domain.vo.SelectRoleByIdVO;
import com.zhangzhan.domain.vo.SelectUserVO;
import com.zhangzhan.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 张一恒
 * @version 1.0
 * @description:
 * @date 2022/12/7 14:51
 */
@RestController
@RequestMapping("/system/role")
public class SystemRoleController {

    @Autowired
    private RoleService roleService;

    /**
     * @description 角色分页查询
     * @param pageNum
     * @param pageSize
     * @param roleLikeDto
     * @return com.zhangzhan.domain.commcon.ResponseResult<com.zhangzhan.domain.vo.PageVO>
     * @author 31115
     * @date 2022/12/7 14:55
     */
    @GetMapping("/list")
    public ResponseResult<PageVO> pageList(Integer pageNum, Integer pageSize, RoleLikeDto roleLikeDto) {
        return roleService.pageList(pageNum, pageSize, roleLikeDto);
    }

    /**
     * @description 修改状态
     *
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 15:10
     */
    @PutMapping("/changeStatus")
    public ResponseResult changeStatus(@RequestBody ChangeStatusDto change){
        return roleService.changeStatus(change);
    }

    /**
     * @description 新增
     *
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 21:12
     */
    @PostMapping
    public ResponseResult saveRoleMenu(@RequestBody SaveRoleMenuDto saveRoleMenuDto){
        return roleService.saveRoleMenu(saveRoleMenuDto);
    }


    /**
     * @description 修改回显
     * @param id
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 21:41
     */
    @GetMapping("{id}")
    public ResponseResult<SelectRoleByIdVO> selectRoleById(@PathVariable Long id){
        return roleService.selectRoleById(id);
    }

    /**
     * @description 更新角色
     * @param updateRoleMenuDto
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 22:40
     */
    @PutMapping
    public ResponseResult updateRole(@RequestBody UpdateRoleMenuDto updateRoleMenuDto){
        return roleService.updateRole(updateRoleMenuDto);
    }

    /**
     * @description 批量删除
     * @param ids
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/8 0:11
     */
    @DeleteMapping("{id}")
    public ResponseResult deleteRoleById(@PathVariable(value = "id") Long[] ids){
        return roleService.deleteRoleById(ids);
    }

    /**
     * @description 查询角色列表接口
     * @param
     * @return
     * @author 31115 
     * @date 2022/12/8 9:31
     */
    @GetMapping("/listAllRole")
    public ResponseResult<SelectUserVO> listAllRole(){
        return roleService.listAllRole();
    }

}
